package com.server.llh.llhserverwork.activity.food;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.lelaohui.net.BaseLeLaohuiAcitivity;
import com.lelaohui.net.netmanager.INetRequestManager;
import com.lelaohui.net.netmanager.NetRequestManager;

import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.adapter.base.ListFragmentPagerAdapter;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ZTF on 2017-05-27.
 */

public class LlhFoodOrderFragment extends BaseLeLaohuiAcitivity implements BottomNavigationBar.OnTabSelectedListener {
    @BindView(R.id.left_btn)
    ImageButton leftBtn;
    @BindView(R.id.titlebar_text)
    TextView titlebarText;
    @BindView(R.id.right_btn)
    Button rightBtn;
    @BindView(R.id.bottom_navigation_bar)
    BottomNavigationBar bottomNavigationBar;
    ViewPager mViewPager;
    private ArrayList<Fragment> list = new ArrayList<Fragment>();
    ListFragmentPagerAdapter mPagerAdapter;
    private final int FIRST_FRAGMENT = 0;
    private final int SECOND_FRAGMENT = 1;
    private final int THREE_FRAGMENT = 2;
    private final int FOUR_FRAGMENT = 3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        titlebarText.setText("餐饮订单");
        rightBtn.setVisibility(View.VISIBLE);
        rightBtn.setText("更多");
        rightBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getApplicationContext(),   FoodOrderAllFragment.class);
                startActivity(intent);
            }
        });
        mViewPager = (ViewPager) findViewById(R.id.id_vp_viewpager);
        mViewPager.setOffscreenPageLimit(1);
        list.add(LlhFoodOrderPayOkFragment.newInstance(FIRST_FRAGMENT));
        list.add(LlhFoodOrderPayOkFragment.newInstance(SECOND_FRAGMENT));
        list.add(LlhFoodOrderPayOkFragment.newInstance(THREE_FRAGMENT));
        list.add(LlhFoodOrderPayOkFragment.newInstance(FOUR_FRAGMENT));
        bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);
        bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC);
        bottomNavigationBar
                .addItem(new BottomNavigationItem(R.mipmap.llh_server_order_icon_1, "待支付").setActiveColorResource(R.color.orange1))
                .addItem(new BottomNavigationItem(R.mipmap.llh_server_order_icon_2, "待发货").setActiveColorResource(R.color.red))
                .addItem(new BottomNavigationItem(R.mipmap.llh_address_icon_2, "待确认").setActiveColorResource(R.color.qian_lan_se))
                .addItem(new BottomNavigationItem(R.mipmap.llh_server_order_icon_4, "待评论").setActiveColorResource(R.color.orange))
                .setFirstSelectedPosition(0)
                .initialise();
        bottomNavigationBar.setTabSelectedListener(this);
        mPagerAdapter = new ListFragmentPagerAdapter(getSupportFragmentManager(), list, 4);
        mViewPager.setAdapter(mPagerAdapter);
        mViewPager.setOnPageChangeListener(onPageChangeListener);
    }

    private ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {

            bottomNavigationBar.selectTab(position);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    };


    @Override
    public void onTabSelected(int position) {
        mViewPager.setCurrentItem(position);
    }

    @Override
    public void onTabUnselected(int position) {

    }

    @Override
    public void onTabReselected(int position) {

    }

    @OnClick(R.id.left_btn)
    public void onViewClicked() {
        onBackPressed();
    }

    @Override
    public void showProgress() {


    }

    @Override
    public void hideProgress() {

    }

    @Override
    protected int getlayout() {
        return R.layout.llh_order_fragment;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void doBasess() {

    }

    @Override
    protected INetRequestManager getRequestManager() {
        return NetRequestManager.getInstance();
    }
}
